#include "searchlineedit.h"

SearchLineEdit::SearchLineEdit(QWidget *parent,QStringList list) :
    QLineEdit(parent)
{
    this->setPlaceholderText( "搜索" );
    this->setMaximumSize(800,30);
    this->setWindowFlag(Qt::FramelessWindowHint);
    if(!list.isEmpty())
        SetContent(list);
    connect(completer,SIGNAL(activated(QString)),this,SLOT(ChooseSlot(QString)));
}

SearchLineEdit::SearchLineEdit(QWidget *parent):QLineEdit(parent)
{
    this->setPlaceholderText( "搜索" );
    this->setMaximumSize(800,30);
    this->setWindowFlag(Qt::FramelessWindowHint);
    connect(completer,SIGNAL(activated(QString)),this,SLOT(ChooseSlot(QString)));
}

SearchLineEdit::SearchLineEdit(QWidget *parent, QStringListModel* listmodel)
{
    this->setPlaceholderText( "搜索" );
    this->setMaximumSize(800,30);
    this->setWindowFlag(Qt::FramelessWindowHint);
    listModel = listmodel;
    completer = new QCompleter(this);
    completer->setModel(listModel);
    completer->setFilterMode(Qt::MatchContains);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    this->setCompleter(completer);
    connect(completer,SIGNAL(activated(QString)),this,SLOT(ChooseSlot(QString)));
}

SearchLineEdit::~SearchLineEdit()
{
}

void SearchLineEdit::SetContent(QStringList &list)
{
    listModel = new QStringListModel(this);
    listModel->setStringList(list);
    completer = new QCompleter(this);
    completer->setModel(listModel);
    completer->setFilterMode(Qt::MatchContains);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    this->setCompleter(completer);
}

void SearchLineEdit::ChooseSlot(QString s)
{
    emit this->Choose(s);
}

void SearchLineEdit::RefreshList(QStringList list)
{
    listModel->setStringList(list);
}

